import {defineConfig, loadEnv} from 'vite'
import {handleEnv} from './build/utils/helper'
import {createProxy} from './build/vite/proxy'
import {createVitePlugins} from './build/plugins'
import {buildOptions} from './build/vite/build'

export default defineConfig(({mode}) => {
    const root = process.cwd()
    const env = loadEnv(mode, root)
    const viteEnv = handleEnv(env)
    const {VITE_SERVER_PORT, VITE_PROXY} = viteEnv

    return {
        plugins: createVitePlugins(),
        resolve: {
            alias: {
                '@': '/src',
                '#': '/types'
            }
        },
        css: {
            preprocessorOptions: {
                less: {
                    javascriptEnabled: true,
                    charset: false
                },
            },
        },
        test: {
            environment: 'jsdom',
            globals: true,
            setupFiles: './tests/index.ts'
        },
        server: {
            open: true,
            port: VITE_SERVER_PORT,
            proxy: createProxy(VITE_PROXY)
        },
        esbuild: {
            pure: ["console.log", "debugger"]
        },
        build: buildOptions()
    }
})
